package com.ipzoe.common.core.response;

import lombok.Data;

import java.io.Serializable;

/**
 * 重写GUNS里的responseData 解决其无法适配swagger的问题
 *
 * @param <T>
 * @author eric
 */
@Data
public class
ResponseData<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    public static final String DEFAULT_SUCCESS_MESSAGE = "请求成功";

    public static final String DEFAULT_ERROR_MESSAGE = "网络异常";

    public static final Integer DEFAULT_SUCCESS_CODE = 200;

    public static final Integer DEFAULT_ERROR_CODE = 500;

    /**
     * 请求是否成功
     */
    private Boolean success;

    /**
     * 响应状态码
     */
    private Integer code;

    /**
     * 响应信息
     */
    private String message;

    /**
     * 响应对象
     */
    private T data;

    public ResponseData() {
    }

    public ResponseData(Boolean success, Integer code, String message, T data) {
        this.success = success;
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static SuccessResponseData success() {
        return new SuccessResponseData();
    }

    public static <T> SuccessResponseData success(T t) {
        return new SuccessResponseData(t);
    }

    public static <T> SuccessResponseData success(Integer code, String message, T t) {
        return new SuccessResponseData(code, message, t);
    }

    public static <T> ErrorResponseData<T> error(String message) {
        return new ErrorResponseData<T>(message);
    }

    public static <T> ErrorResponseData<T> error(Integer code, String message) {
        return new ErrorResponseData<T>(code, message);
    }

    public static <T> ErrorResponseData<T> error(Integer code, String message, T object) {
        return new ErrorResponseData<T>(code, message, object);
    }

}
